package com.neusoft.demo3.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neusoft.demo3.bean.Banner;
import com.neusoft.demo3.bean.Goods;
import com.neusoft.demo3.config.AjaxResult;
import com.neusoft.demo3.mapper.GoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//try{
//List<Banner> list= bannerMapper.selectList(null);
//            return AjaxResult.success(list);
//        }catch(Exception e){
//        e.printStackTrace();
//            return AjaxResult.exception(e.getMessage());
//        }
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsMapper goodsMapper;
    @GetMapping("list")
     public  Object findgoods(){
         try{
             List<Goods> list=goodsMapper.selectList(null);
             return AjaxResult.success(list);
         }catch(Exception e){
             e.printStackTrace();
             return AjaxResult.exception(e.getMessage());
         }

     }

    @GetMapping("listByCateId")
    public Object listByCateId(@RequestParam Integer cateId) {
        try {
            QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("cate_id", cateId); // 过滤 cate_id 等于传入值的商品
            List<Goods> list = goodsMapper.selectList(queryWrapper);
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.exception(e.getMessage());
        }
    }
}
